from appium.webdriver.common.appiumby import AppiumBy
from selenium.webdriver import Keys

from Page.base_page import AppBasePage


class IndexPage(AppBasePage):

    def __init__(self):
        super().__init__()
        # 首页
        self.home_locator = (AppiumBy.ID, 'com.tpshop.malls:id/home_ll')
        self.classify_locator = (AppiumBy.ID, 'com.tpshop.malls:id/category_ll')
        self.cart_locator = (AppiumBy.ID, 'com.tpshop.malls:id/cart_ll')
        self.mine_locator = (AppiumBy.ID, 'com.tpshop.malls:id/mine_ll')
        self.search_box_locator = (AppiumBy.CLASS_NAME, 'android.widget.EditText')
        self.search_bth_locator = (AppiumBy.ID, 'com.tpshop.malls:id/search_btn')

    # 打开app
    # def start_app(self):
    #
    # self.find_el(*(AppiumBy.XPATH, '//android.widget.TextView[@text="TP商城单商户"]')).click()
    # 首页
    def go_home(self):
        self.find_el(*self.home_locator).click()

    # 分类
    def go_classify(self):
        self.find_el(*self.classify_locator).click()

    # 购物车
    def go_carts(self):
        self.find_el(*self.cart_locator).click()

    # 我的
    def go_mine(self):
        self.find_el(*self.mine_locator).click()

    # 搜索商品
    def search_goods(self, keyword):
        # android.widget.EditText
        self.find_el(*self.search_box_locator).click()
        self.input_text(self.find_el(*self.search_box_locator), keyword)
        self.find_el(*self.search_bth_locator).click()
